//
//  MyBizeScrVIew.m
//  ZITHER
//
//  Created by weixin on 2018/11/23.
//  Copyright © 2018 weixn. All rights reserved.
//

#import "MyBizeScrVIew.h"

@implementation MyBizeScrVIew


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    }
    return self;
}






-(void)addScrImage1:(NSArray *)arr{
    
    if (arr.count == 0 || arr == nil) {
        return;
    }
    
    self.arrMImage = [[NSMutableArray alloc]init];

    self.hidden = NO;
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.contentSize = CGSizeMake(arr.count*68,0);
    

    
    for (int j = 0; j<arr.count; j++) {
      
        BaseImageV *imageV = [[BaseImageV alloc]initializeFrame:CGRectMake(j*90,50, 40,40) contentMode:2];
        CGFloat height = 0;
        if (j == 0) {
            height = 80;
            [imageV setCornerRadiusWithRadius:40 isMasks:YES];
            [imageV setBorderWithColor:[UIColor blackColor] width:2];
            self.lastImage = imageV;
        }else{
            height = 40;
            [imageV setCornerRadiusWithRadius:20 isMasks:YES];
            [imageV setBorderWithColor:[UIColor whiteColor] width:2];
        }


        NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,arr[j]];
        [imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"watchSmale"]];
        
        imageV.backgroundColor = [UIColor randomColor];
        imageV.tag = 100+j;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            if (self.block) {
                self.block(j);
            }
            if ([imageV isEqual:self.lastImage]) {
                return ;
            }
            [UIView animateWithDuration:0.1 animations:^{
                [imageV setCornerRadiusWithRadius:40 isMasks:YES];
                [imageV setBorderWithColor:[UIColor blackColor] width:2];
                [self.lastImage setCornerRadiusWithRadius:20 isMasks:YES];
                [self.lastImage setBorderWithColor:[UIColor whiteColor] width:2];
                [self.lastImage mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.width.height.mas_equalTo(40);
                }];
                [imageV mas_updateConstraints:^(MASConstraintMaker *make) {
                    make.width.height.mas_equalTo(80);
                }];
                self.lastImage = imageV;
            }];
            
        }];
        imageV.userInteractionEnabled = YES;
        [imageV addGestureRecognizer:tap];
        [self addSubview:imageV];
        
        
        [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.mas_centerY).offset(0);
            make.centerX.equalTo(self.mas_left).offset(50+j*90);
            make.width.height.mas_equalTo(height);
        }];
   
        [self.arrMImage addObject:imageV];
    }
    self.contentSize = CGSizeMake(arr.count*90+100, 0);
}


-(NSMutableArray *)arrMImage{
    if (!_arrMImage) {
        _arrMImage = [[NSMutableArray alloc]init];
    }
    return _arrMImage;
}
@end
